<template>
  <page-main>
    <el-tabs tab-position="left" style="height: 600px;">
      <el-tab-pane label="常规设置">
        <el-form label-position="left" label-width="120px" :model="routine_form_data">
          <el-form-item label="登录验证码">
            <el-switch v-model="routine_form_data.loginCheck"></el-switch>
          </el-form-item>
          <el-form-item label="显示公告">
            <el-switch v-model="routine_form_data.noticeVisable"></el-switch>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="settings_Set_Routine()">保存</el-button>
            <el-button @click="settings_Get_Routine()">重置</el-button>
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="对象存储设置">
        <el-form label-position="left" label-width="120px" :model="oss_form_data">
          <el-form-item label="endpoint">
            <el-input v-model="oss_form_data.endpoint"></el-input>
          </el-form-item>
          <el-form-item label="accessKeyId">
            <el-input v-model="oss_form_data.accessKeyId"></el-input>
          </el-form-item>
          <el-form-item label="accessKeySecret">
            <el-input v-model="oss_form_data.accessKeySecret"></el-input>
          </el-form-item>
          <el-form-item label="bucketName">
            <el-input v-model="oss_form_data.bucketName"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="settings_Set_OSSConfig()">保存</el-button>
            <el-button @click="settings_Get_OSSConfig()">重置</el-button>
          </el-form-item>
        </el-form>
      </el-tab-pane>
    </el-tabs>
  </page-main>
</template>

<script>
import { setOSSConfig, getOSSConfig, setRoutineConfig, getRoutineConfig } from '@/api/requests/admin'
import { success } from '@/util/message'
export default {
  data () {
    return {
      oss_form_data: {},
      routine_form_data: {}
    }
  },
  created () {
    this.settings_Get_OSSConfig()
    this.settings_Get_Routine()
  },
  methods: {
    settings_Get_OSSConfig () {
      getOSSConfig().then(res => {
        this.oss_form_data = JSON.parse(res.data.value)
      })
    },
    settings_Set_OSSConfig () {
      setOSSConfig(this.oss_form_data).then(res => {
        if (res.code == 200) {
          success(this, '保存成功')
        }
      })
    },
    settings_Get_Routine () {
      getRoutineConfig().then(res => {
        this.routine_form_data = JSON.parse(res.data.value)
      })
    },
    settings_Set_Routine () {
      setRoutineConfig(this.routine_form_data).then(res => {
        if (res.code == 200) {
          success(this, '保存成功')
        }
      })
    }
  },
}
</script>
<style lang="scss" scoped>
.el-tabs {
    .el-tabs__header .el-tabs__nav {
        .el-tabs__active-bar {
            z-index: 0;
            width: 100%;
            background-color: #e1f0ff;
            border-right: 2px solid #409eff;
        }
        .el-tabs__item {
            text-align: left;
            padding-right: 100px;
        }
    }
    .el-tab-pane {
        padding: 0 20px 0 30px;
    }
}
.el-input {
    width: 60%;
}
</style>